<?php

class AdminAction extends CommonAction {

        protected $_templateModule = NULL;

        //初始化
        public function _initialize() {
                $this->_templateModule = D(MODULE_NAME);
        }

        //列表展示 方法 只输出模板,不作其他操作
        public function index() {
                $this->display();
        }

        /**
         * 录入信息页面
         */
        public function add() {
                $this->display("process");
        }

        /**
         * 录入信息 程序逻辑操作
         */
        public function save() {
                if (FALSE === $this->_templateModule->create()) {
                        $this->error($this->_templateModule->getError());
                }
                if (empty($this->_templateModule->{$this->_templateModule->getPk()})) {

                        unset($this->_templateModule->{$this->_templateModule->getPk()});

                        if (FALSE === $this->_templateModule->add()) {
                                $this->error($this->_templateModule->getDbError());
                        }
                } else {
                        if (FALSE === $this->_templateModule->save()) {
                                $this->error($this->_templateModule->getDbError());
                        }
                }


                $this->success("操作成功", U("index"));
        }

        /**
         * 编辑信息 展示页面
         */
        public function edit() {
                $pk = $this->_templateModule->getPk();
                if ($_REQUEST[$pk]) {
                        $info = $this->_templateModule->find($_REQUEST[$pk]);
                        $this->assign($info);
                }
                $this->display("process");
        }

        /**
         * 删除操作
         */
        public function delete() {
                if (IS_POST) {
                        $ids = I("post.ids");

                        $delkey = implode(",", $ids);
                } else {
                        $pk = $this->_templateModule->getPk();
                        $delkey = I("get.$pk");
                }
                if (FALSE === $this->_templateModule->delete($delkey)) {
                        $this->error($this->_templateModule->getDbError());
                }
                $this->success("删除成功", U("index"));
        }

}

?>
